/**
 * @properties={typeid:24,uuid:"D51798D5-61AC-40C5-94CE-9FA2C1AC4B7B"}
 */
function guardar() {
	if (codigo == null || descripcion == null || moneda_id == null || desayuno == null)
	{
		globals.DIALOGS.showWarningDialog('Aviso','Por favor, ingrese todos los campos obligatorios','OK')
		return false
	}
	if (valida() == false)
	{
		globals.DIALOGS.showErrorDialog('Aviso','El código ya existe. Por favor, ingrese otro','OK')
		return false
	}
	if (databaseManager.saveData() == true)
	{
		globals.DIALOGS.showInfoDialog('Aviso','Datos modificados con éxito','OK')
		return true
	}
	else
	{
		globals.DIALOGS.showWarningDialog('Aviso','Ocurrio un error al grabar. Inténtelo nuevamente', 'OK')
		return false
	}
}

/**
 * @properties={typeid:24,uuid:"57E06E33-626B-448F-961D-F6EF81999232"}
 */
function valida()
{
	var $sql = 'SELECT tarifa_id FROM tarifas WHERE upper(codigo) = upper(?) AND hotel_id = ? AND tarifa_id = ?'
	var $args = [codigo, globals.gHotelId, tarifa_id]
	var $ds = databaseManager.getDataSetByQuery('hoteleria',$sql,$args,-1)
	if ($ds.getMaxRowIndex() == 0)
		return true
	return false
}

/**
 * @properties={typeid:24,uuid:"BBEC8B2B-5BE6-4D5D-BFA0-2A0DD379F4F4"}
 */
function cancelar() {
	databaseManager.revertEditedRecords()
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"831DA043-B365-400C-8BCD-72A297A4EAA3"}
 */
function onShow(firstShow, event) {
	databaseManager.setAutoSave(false)
}

/**
 * Handle hide window.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"4923839A-8DDF-4BC3-9B18-E081B45BA0FE"}
 */
function onHide(event) {
	databaseManager.revertEditedRecords()
	return true
}
